#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

char* const env[]=
{
    (char* const)"MYENV=123456",
   (char* const)"MYENV1=11111",
    (char* const)"MYENV2=22222",
    NULL
};

int main()
{
    printf("begin\n");
    if(fork()==0)
    {
        printf("child pid is : %d\n",getpid());
       // int n=execl("/usr/bin/ls","ls","-a","-l",NULL);
       // execl("./other","other",NULL);
       //execlp("ls","ls","-a","-l",NULL);
       

        //char* const argv[]={(char* const)"ls",(char* const)"-a",(char* const)"-l",NULL};
        char* const argv[]=
        {
            (char* const)"other",
            (char* const)"-a",
            (char* const)"-b",
            (char* const)"-c",
            (char* const)"-d",
            NULL
        };

        //execv("/usr/bin/ls",argv);
        //execvp("ls",argv);
       int i=0;
       for(i=0;env[i];i++)
       {
           putenv(env[i]);
       }

       extern char** environ;
       execvpe("./other",argv,environ);
        exit(1);
    }

    waitpid(-1,NULL,0);

    printf("end\n");

}


//int main()
//{
//    printf("begin\n");
//    int n=execl("/usr/bin/ls","ls","-a","-l",NULL);
//    exit(1);
//    printf("end\n");
//}
